package com.watson.quartzdemo.controller;

import com.watson.quartzdemo.manager.QuartzManager;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 天空蓝蓝的
 */
@RestController
public class ModifyCronController {

    @Autowired
    private QuartzManager quartzManager;

    @GetMapping("start")
    public String start(@RequestParam String job, @RequestParam String group) throws SchedulerException {
        /**10秒执行一次*/
        String cron = "*/9 * * * * ?";
        quartzManager.startJobTask(job, group,cron);
        return "ok";
    }
    @GetMapping("pauseJob")
    public String pauseJob(@RequestParam String job, @RequestParam String group) throws SchedulerException {
        quartzManager.pauseJob(job, group);
        return "ok";
    }

    @GetMapping("modify")
    public String modify(@RequestParam String job, @RequestParam String group) throws SchedulerException {
        /**10秒执行一次*/
        String cron = "*/10 * * * * ?";
        quartzManager.modifyJob(job, group,cron);
        return "ok";
    }
}
